package com.bjpowernode.boss.convert;

import com.bjpowernode.boss.domain.PayWay;
import com.bjpowernode.boss.enums.buz.PublicStatus;
import com.bjpowernode.boss.mvc.model.vo.PayWayVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;

import java.util.List;

/**
 * 支付方式 数据类型转换
 */
@Mapper(componentModel = "spring")
public interface PayWayConvert {

    // List<PayWay> --->  List<PayWayVo>
    List<PayWayVo> toConvertPayWayVoList(List<PayWay> payWay);

    // payway  --->  paywayvo
    @Mappings({
            @Mapping(source = "payProductCode" , target = "productCode"),
            @Mapping(source = "status" , target = "status" , qualifiedByName = "handleStatusConvert"),
            @Mapping(source = "editTime" , target = "editTime" , dateFormat = "yyyy-MM-dd HH:mm:ss")
    })
    PayWayVo toVonvertPayWayVo(PayWay payWay);

    // status  enable | disable  ----> 禁用 , 启用
    @Named("handleStatusConvert")
    default String handleStatusConvert(String status) {
        String newStatus = PublicStatus.ENABLE.getMsg();
        if (!PublicStatus.ENABLE.name().equals(status)) {
            newStatus = PublicStatus.DISABLE.getMsg();
        }
        return newStatus;
    }


}
